package com.bl.andr.utillib;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/**
 * desc:
 * creator: fishbaby
 * date:    2016/2/22/0022
 */
public class ToastUtil {
    private static ToastUtil instance;

    private static Toast mCustomToast = null;


    private View mCustomLayout;
    private TextView mTvContent;


    public static ToastUtil getInstance() {
        if (instance == null) {
            instance = new ToastUtil();
        }
        return instance;
    }

// *************************************************************************
// 自定义(涉及到布局)，请在具体项目中实现
// *************************************************************************

  /*  public void showErrorNoDelay(String showText) {
        showCustomNoDelay(showText, Toast.LENGTH_SHORT);
    }

    public void showErrorNoDelay(int resId) {
        showErrorNoDelay(ResUtil.getString(resId));
    }

    public void showCorrectNoDelay(String showText) {
        showCustomNoDelay(showText, Toast.LENGTH_SHORT);
    }

    public void showCorrectNoDelay(int resId) {
        showCorrectNoDelay(mContext.getString(resId));
    }

    private void toastWithIcon(String tip, int drawableResID) {
        showCustomNoDelay(tip, Toast.LENGTH_LONG);
        if (drawableResID > 0) {
            ViewUtil.setTextViewDrawable(mTvContent, R.drawable.toast_icon_warn, 1);
        }
    }


    public void toastWithIconC(String str) {
        toastWithIcon(str, R.drawable.toast_icon_correct);
    }

    public void toastWithIconC(int resId) {
        toastWithIconC(ResUtil.getString(resId));
    }

    public void toastError(String str) {
        showCustomNoDelay(str, Toast.LENGTH_LONG);
        *//* ResUtil.setTextViewDrawable(mTvContent, R.drawable.icon_toast_warn, 1);*//*
    }

    public void toastError(int resId) {
        toastError(ResUtil.getString(resId));
    }


    public interface OnToastDismissListener {
        void onToastDismiss();
    }


    *//**
     * @param showText 提示内容
     *//*
    @SuppressLint("InflateParams")
    private void showCustomNoDelay(Context context,String showText, int duration) {
        if (mCustomToast == null) {
            mCustomToast = new Toast(context);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);

            mCustomLayout = inflater.inflate(R.layout.custom_toast, null);
            mCustomToast.setView(mCustomLayout);
            mCustomToast.setGravity(Gravity.CENTER, 0, 0);
            mCustomToast.setDuration(duration);
        }
        mTvContent = (TextView) mCustomLayout.findViewById(R.id.toast_tv);
        mTvContent.setText(showText);
        mCustomToast.show();
    }
*/


// *************************************************************************
// 系统默认提示
// *************************************************************************

    private static Toast mToast = null;

    /**
     * 避免多次点击,弹出多个toast
     */
    @SuppressLint("ShowToast")
    public static void show(Context context, String text) {
        if (mToast == null) {
            mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public void showS(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    public void showS(Context context, int resId) {
        showS(context, context.getString(resId));
    }

    public void showL(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

    public void showL(Context context, int resId) {
        showL(context, context.getString(resId));
    }


}
